package com.sy.controller.finance;

import com.sy.bean.finance.FinanceAccount;
import com.sy.bean.finance.param.FinancePage;
import com.sy.bean.finance.utils.BeanToMap;
import com.sy.common.bean.ResultBean;
import com.sy.service.finance.FinanceAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/finance/account")
@Api(tags = "finance-财务账户管理")
public class FinanceAccountController extends MyFinanceBaseController {
    @Autowired
    FinanceAccountService accountService;

    @GetMapping("/{account_id}")
    @ApiOperation("查询账户信息(根据id)")
    public ResultBean query(@PathVariable("account_id") Integer id){
        return selectResult(accountService.get(id));
    }

    @GetMapping("/page")
    @ApiOperation("查询账户列表(分页)")
    public ResultBean query(FinancePage page){
        return selectResult(accountService.query(BeanToMap.getMap(page)));
    }

    @PostMapping("/")
    @ApiOperation("新增账户")
    public ResultBean save(@RequestBody FinanceAccount account){
        return saveResult(accountService.save(account));
    }

    @PutMapping("/")
    @ApiOperation("修改账户信息(根据科目id)")
    public ResultBean updateNote(@RequestBody FinanceAccount account){
        int affect = 0;
        if (account.getId() != null){
            affect = accountService.update(account);
        }
        return updateResult(affect);
    }

    @DeleteMapping("/{account_id}")
    @ApiOperation("删除科目(根据id逻辑删除)")
    public ResultBean delete(@PathVariable("account_id") Integer id){
        int affect = 0;
        if (id != null){
            affect = accountService.delete(id);
        }
        return deleteResult(affect);
    }
}
